package com.ruoyi.customerSample.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.customerSample.domain.EntrustedBills;
import com.ruoyi.customerSample.service.IEntrustedBillsService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 检测检验委托单据Controller
 * 
 * @author ruoyi
 * @date 2023-10-23
 */
@RestController
@RequestMapping("/backSample/entrustedBills")
@Api(value="检测检验委托单据",tags = "检测检验委托单据接口")
public class EntrustedBillsController extends BaseController
{
    @Autowired
    private IEntrustedBillsService entrustedBillsService;

    /**
     * 查询检测检验委托单据列表
     */
    @GetMapping("/list")
    @ApiOperation(value="查询检测检验委托单据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "页数", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "每页记录数", required = true, dataType = "String"),
    })
    public TableDataInfo list(EntrustedBills entrustedBills)
    {
        startPage();
        List<EntrustedBills> list = entrustedBillsService.selectEntrustedBillsList(entrustedBills);
        return getDataTable(list);
    }

    /**
     * 导出检测检验委托单据列表
     */
    @Log(title = "检测检验委托单据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EntrustedBills entrustedBills)
    {
        List<EntrustedBills> list = entrustedBillsService.selectEntrustedBillsList(entrustedBills);
        ExcelUtil<EntrustedBills> util = new ExcelUtil<EntrustedBills>(EntrustedBills.class);
        util.exportExcel(response, list, "检测检验委托单据数据");
    }

    /**
     * 获取检测检验委托单据详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value="获取检测检验委托单据详细信息")
    @ApiImplicitParam(paramType="query", name = "id", value = "主键", required = true, dataType = "String")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(entrustedBillsService.selectEntrustedBillsById(id));
    }


    /**
     * 获取检测检验委托单据最大编号
     */
    @GetMapping(value = "/getMaxNum/{testYear}")
    @ApiOperation(value="获取检测检验委托单据最大编号")
    @ApiImplicitParam(paramType="query", name = "testYear", value = "检测年份", required = true, dataType = "String")
    public AjaxResult getMaxNum(@PathVariable("testYear") String testYear)
    {
        return success(entrustedBillsService.selectEntrustedNumMax(testYear));
    }


    /**
     * 新增检测检验委托单据
     */
    @Log(title = "检测检验委托单据", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value="新增检测检验委托单据")
    public AjaxResult add(@ApiParam(name="检测检验委托单据",value="传入json格式",required=true)@RequestBody EntrustedBills entrustedBills)
    {
        return toAjax(entrustedBillsService.insertEntrustedBills(entrustedBills));
    }

    /**
     * 修改检测检验委托单据
     */
    @Log(title = "检测检验委托单据", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value="修改检测检验委托单据")
    public AjaxResult edit(@ApiParam(name="检测检验委托单据",value="传入json格式",required=true)@RequestBody EntrustedBills entrustedBills)
    {
        return toAjax(entrustedBillsService.updateEntrustedBills(entrustedBills));
    }

    /**
     * 删除检测检验委托单据
     */
    @Log(title = "检测检验委托单据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation(value="删除检测检验委托单据")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(entrustedBillsService.deleteEntrustedBillsByIds(ids));
    }
}
